// Copyright (C) 1953-2024 NUDT
// Verilog module name - multicast_packet_lookup
// Version: V4.3.0.20240125
// Created:
//         by - fenglin
////////////////////////////////////////////////////////////////////////////
// Description:
//     multicast_packet_lookup   
///////////////////////////////////////////////////////////////////////////

module multicast_packet_lookup(                        
    i_clk                                   ,
    i_rst_n                                 ,

    iv_md_epl2mpl                           ,
    i_md_wr_epl2mpl                         ,

    iv_ipram_addr_cpe2ram                   ,
    iv_ipram_wdata_cpe2ram                  ,
    i_ipram_wr_cpe2ram                      ,
    i_ipram_rd_cpe2ram                      ,
    ov_ipram_rdata_ram2cpe                  ,

    iv_droute_portbm_cpe2tlp                ,
    iv_sroute_portbm_cpe2tlp                ,
    i_unknown_multicast_forwardmode_cpe2tlp ,

    ov_md_mpl2tlp                           ,
    o_md_wr_mpl2tlp                         
);

// I/O
input   wire                i_clk                                   ;
input   wire                i_rst_n                                 ;

input   wire    [299:0]     iv_md_epl2mpl                           ;
input   wire                i_md_wr_epl2mpl                         ;

input   wire    [2:0]       iv_ipram_addr_cpe2ram                   ;
input   wire    [64:0]      iv_ipram_wdata_cpe2ram                  ;
input   wire                i_ipram_wr_cpe2ram                      ;
input   wire                i_ipram_rd_cpe2ram                      ;
output  wire    [64:0]      ov_ipram_rdata_ram2cpe                  ;

input   wire    [31:0]      iv_droute_portbm_cpe2tlp                ;
input   wire    [31:0]      iv_sroute_portbm_cpe2tlp                ;
input   wire                i_unknown_multicast_forwardmode_cpe2tlp ;

output  wire    [299:0]     ov_md_mpl2tlp                           ;
output  wire                o_md_wr_mpl2tlp                         ;

//***************************************************
//               packet generate
//***************************************************
// internal reg&wire 
wire            w_fifo_empty_fifo2mlu   ;
wire            w_fifo_rd_mlu2fifo      ;
wire    [299:0] wv_md_fifo2mlu          ;

wire            w_ipram_rd_mlu2ram      ;
wire    [2:0]   wv_ipram_raddr_mlu2ram  ;
wire    [64:0]  wv_ipram_rdata_ram2mlu  ;


syncfifo_showahead_sclr_w300d64 syncfifo_showahead_sclr_w300d64_inst (
		.data  (iv_md_epl2mpl),  //  fifo_input.datain
		.wrreq (i_md_wr_epl2mpl), //            .wrreq
		.rdreq (w_fifo_rd_mlu2fifo), //            .rdreq
		.clock (i_clk), //            .clk
		.q     (wv_md_fifo2mlu),     // fifo_output.dataout
		.usedw (), //            .usedw
		.full  (),  //            .full
		.empty (w_fifo_empty_fifo2mlu)  //            .empty
	);

truedualportram_singleclock_rdenab_outputaclrab_w65d8 truedualportram_singleclock_rdenab_outputaclrab_w65d8_inst (
		.data_a    (iv_ipram_wdata_cpe2ram),    //  ram_input.datain_a
		.data_b    (),    //           .datain_b
		.address_a (iv_ipram_addr_cpe2ram), //           .address_a
		.address_b (wv_ipram_raddr_mlu2ram), //           .address_b
		.wren_a    (i_ipram_wr_cpe2ram),    //           .wren_a
		.wren_b    (),    //           .wren_b
		.inclock   (i_clk),   //           .inclock
		.outclock  (i_clk),  //           .outclock
		.rden_a    (i_ipram_rd_cpe2ram),    //           .rden_a
		.rden_b    (w_ipram_rd_mlu2ram),    //           .rden_b
		.q_a       (ov_ipram_rdata_ram2cpe),       // ram_output.dataout_a
		.q_b       (wv_ipram_rdata_ram2mlu)        //           .dataout_b
	);




multicast_lookup multicast_lookup_inst(                        
    .i_clk                                   (i_clk   ),
    .i_rst_n                                 (i_rst_n ),

    .i_fifo_empty_fifo2mlu                   (w_fifo_empty_fifo2mlu),
    .o_fifo_rd_mlu2fifo                      (w_fifo_rd_mlu2fifo   ),
    .iv_md_fifo2mlu                          (wv_md_fifo2mlu       ),

    .o_ipram_rd_mlu2ram                      (w_ipram_rd_mlu2ram    ),
    .ov_ipram_raddr_mlu2ram                  (wv_ipram_raddr_mlu2ram),
    .iv_ipram_rdata_ram2mlu                  (wv_ipram_rdata_ram2mlu),

    .iv_droute_portbm_cpe2tlp                (iv_droute_portbm_cpe2tlp               ),
    .iv_sroute_portbm_cpe2tlp                (iv_sroute_portbm_cpe2tlp               ),
    .i_unknown_multicast_forwardmode_cpe2tlp (i_unknown_multicast_forwardmode_cpe2tlp),

    .ov_md_mpl2tlp                           (ov_md_mpl2tlp  ),
    .o_md_wr_mpl2tlp                         (o_md_wr_mpl2tlp)
);

endmodule